<template>
  <div class="app-container">
    <!-- 放置表单 -->
    <el-form ref="userForm" label-width="60px" :model="userData" :rules="rules">
      <el-form-item label="姓名:" prop="username">
        <el-input v-model="userData.username" style="width: 300px" />
      </el-form-item>
      <el-form-item label="手机号:">
        <el-input v-model="userData.mobile" disabled style="width: 300px" />
      </el-form-item>
      <el-form-item label="密码:">
        <el-input
          v-model="userData.password"
          type="password"
          disabled
          style="width: 300px"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="xsaveUserDetailById">更新</el-button>
        <el-button @click="$router.back()">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
// 导入修改员工信息的API
import { saveUserDetailById } from '@/api/employees.js'

export default {
  props: {
    userData: {
      type: Object,
      default: () => { }
    }
  },
  data () {
    return {
      rules: {
        username: [{ required: true, min: 3, max: 16, message: '用户名必填！', trigger: 'change' }]
      }
    }
  },
  methods: {
    xsaveUserDetailById () {
      // 表单验证
      this.$refs.userForm.validate(async flag => {
        console.log(flag)
        console.log(this.userData)
        if (!flag) return
        // 调用接口,修改用户信息
        await saveUserDetailById(this.userData)
        //  提示信息
        this.$message.success('修改成功!')
        // 返回上一级
        this.$router.back()
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
